﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Blackbird.Game.Message
{
    /// <summary>
    /// A class for constructing a server message.
    /// </summary>
    class ServerMessage
    {
        /// <summary>
        /// The id of the message.
        /// </summary>
        private int id;


        /// <summary>
        /// The message body.
        /// </summary>
        private MemoryStream MessageBody;


        public static int MESSAGE_SIZE = 1024;
        /// <summary>
        /// Construct a new instance of the server message class.
        /// </summary>
        /// <param name="id">The id of the message.</param>

        public ServerMessage(int id)
        {
            this.MessageBody = new MemoryStream(ServerMessage.MESSAGE_SIZE);
            this.id = id;
        }

        /// <summary>
        /// Append a raw integer to the buffer.
        /// </summary>
        /// <param name="i">The integer to be written</param>
        public void AppendInt(int i)
        {
            this.MessageBody.WriteByte((byte)i);
        }

        /// <summary>
        /// Append a boolean to the buffer.
        /// </summary>
        /// <param name="b"></param>
        public void AppendBoolean(bool b)
        {
            if (b)
            {
                this.MessageBody.WriteByte(0);
            }
            this.MessageBody.WriteByte(1);
        }

        public void AppendString(string s)
        {
            if (s != null || s != "")
            {
                this.MessageBody.Write(Encoding.UTF8.GetBytes(s),0,s.Length);
            }
            throw new ArgumentException("String cannot be null!");
        }
        


    }
}
